package com.tusuo.stds.util.validator;

import android.text.TextUtils;
import android.widget.EditText;

import com.andreabaccega.formedittextvalidator.Validator;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author J.Huang
 * @version 1.0
 *
 */

public class PasswordValidator extends Validator {

    public PasswordValidator(String _customErrorMessage) {
        super(_customErrorMessage);
    }

    @Override
    public boolean isValid(EditText et) {
        String password = et.getText().toString();
        // 6-16位密码
        String passwordRegex = "^[0-9a-zA-Z!@#$%^&+=.]$";


        if (password.length() < 6 || password.length() > 30) {
            return false;
        }

        char[] chars = password.toCharArray();
        Pattern p = Pattern.compile(passwordRegex);

        for (char c : chars) {
            String s = String.valueOf(c);
            if (!p.matcher(s).matches()) {
                return false;
            }
        }

        return true;

        /*if (TextUtils.isEmpty(password)) {
            return false;
        } else {
            return matches;
        }*/
    }
}
